package practice;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;

public class Practice10 {
    /**
     * 游游的水果大礼包
     * @param args
     */
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextInt();
        long m = in.nextInt();
        long a = in.nextInt();
        long b = in.nextInt();
        long ret = 0;
        // 枚举 1 号礼包的个数
        for (long x = 0; x <= Math.min(n / 2, m); x++) {
            // 计算 2 号礼包的个数
            long y = Math.min(n - x * 2, (m - x) / 2);
            ret = Math.max(ret, a * x + b * y);
        }
        System.out.println(ret);
    }

    /**
     * 买卖股票的最佳时机
     * @param args
     */
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int ret = 0;
        for (int i = 1; i < n; i++) {
            if (arr[i] > arr[i - 1]) {
                ret += arr[i] - arr[i - 1];
            }
        }
        System.out.println(ret);
    }


    /**
     * 倒置字符串
     * @param s
     * @param left
     * @param right
     */
    public static void Reverse(char[] s, int left, int right) {
        int l = left, r = right;
        while (l < r) {
            char ch = s[l];
            s[l] = s[r];
            s[r] = ch;
            l++;
            r--;
        }
    }

    public static void main3(String[] args) throws Throwable{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] s = br.readLine().toCharArray();
        int n = s.length;
        Reverse(s, 0 ,n - 1);
        int left = 0;
        while (left < n) {
            int right = left;
            // 找单词
            while (right < n && s[right] != ' ') {
                right++;
            }
            Reverse(s, left, right - 1);
            // 跳过空格
            while (right < n && s[right] == ' ') {
                right++;
            }
            left = right;
        }
        for (char ch : s) {
            System.out.print(ch);
        }
    }

//    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        char[] ch = in.nextLine().toCharArray();
//        Stack<Character> stack = new Stack<>();
//        StringBuilder str = new StringBuilder();
//        int len = ch.length;
//        for (int i = len - 1; i >= 0; ) {
//            while (i >= 0 && ch[i] != ' ') {
//                stack.push(ch[i]);
//                i--;
//            }
//            while (!stack.isEmpty()) {
//                str.append(stack.pop());
//                if (i > 0 && stack.isEmpty()) {
//                    str.append(' ');
//                    i--;
//                }
//            }
//        }
//        System.out.println(str);
//    }
}
